/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.babble.manage.controller;

import com.babble.manage.dto.ImgCategoryDTO;
import com.babble.manage.dto.QueryImgCategoryDTO;
import com.babble.manage.entity.ImgCategory;
import com.babble.manage.service.IImgCategoryService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 图片分类表 控制器
 *
 * @author Blade
 * @since 2021-11-21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("img/category")
@Api(value = "图片分类模块", tags = "图片分类模块")
public class ImgCategoryController extends BladeController {

	private final IImgCategoryService imgCategoryService;

	@PostMapping
	@ApiOperation(value = "添加分类", notes = "添加图片分类")
	@ApiOperationSupport(order = 1)
	public R<ImgCategory> create(@RequestBody @Validated ImgCategoryDTO categoryDTO) {
		return R.data(imgCategoryService.create(categoryDTO));
	}

	@GetMapping
	@ApiOperation(value = "分类列表", notes = "图片分类列表")
	@ApiOperationSupport(order = 2)
	public R<IPage<ImgCategory>> list(QueryImgCategoryDTO queryImgCategoryDTO) {
		return R.data(imgCategoryService.list(queryImgCategoryDTO));
	}

	@PutMapping("/{id}")
	@ApiOperation(value = "修改分类", notes = "修改图片分类")
	@ApiOperationSupport(order = 3)
	public R<ImgCategory> update(@PathVariable("id") String id,
								 @RequestBody @Validated ImgCategoryDTO categoryDTO) {
		return R.data(imgCategoryService.update(id, categoryDTO));
	}

	@DeleteMapping("/{id}")
	@ApiOperation(value = "删除分类", notes = "删除图片分类")
	@ApiOperationSupport(order = 4)
	public R delete(@PathVariable("id") String id) {
		imgCategoryService.delete(id);
		return R.success("删除成功");
	}

	@GetMapping("/{id}")
	@ApiOperation(value = "获取分类", notes = "获取图片分类")
	@ApiOperationSupport(order = 5)
	public R<ImgCategory> get(@PathVariable("id") String id) {
		return R.data(imgCategoryService.getById(id));
	}
}
